import com.mapper.WorkerMapper;
import com.pojo.Worker;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class WorkerTest {
    @Test
    public void findWorkerByIdTest() {
        SqlSession Session = MyBatisUtils.getSession();
        WorkerMapper mapper = Session.getMapper(WorkerMapper.class);

        Worker worker=mapper.selectworker(1);
        System.out.println(worker);
        Session.close();
    }

    @Test
    public void insertWorkerTest() {
        SqlSession Session = MyBatisUtils.getSession();
        WorkerMapper mapper = Session.getMapper(WorkerMapper.class);
        Worker worker = new Worker();
        worker.setName("赵六");
        worker.setAge(36);
        worker.setSex("女");
        worker.setWorkerId(1004);
        int result = mapper.insertWorker(worker);
        if (result>0){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }
        System.out.println(worker.toString());
        Session.commit();
        Session.close();

    }
    @Test
    public void updateWorkerTest() {
        SqlSession Session = MyBatisUtils.getSession();
        WorkerMapper mapper = Session.getMapper(WorkerMapper.class);
        Worker worker = new Worker();
        worker.setId(4);
        worker.setName("李华");
        worker.setAge(28);
        int result = mapper.updateWorker(worker);
        if (result>0){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }
        System.out.println(worker.toString());
        Session.commit();
        Session.close();
    }
    @Test
    public void deleteWorkerTest() {
        SqlSession Session = MyBatisUtils.getSession();
        WorkerMapper mapper = Session.getMapper(WorkerMapper.class);
        int result=mapper.deleteWorker(4);
        if (result>0){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }
        Session.commit();
        Session.close();
    }
    @Test
    public void selectWorkerByIdAndName() {
        SqlSession Session = MyBatisUtils.getSession();
        WorkerMapper mapper = Session.getMapper(WorkerMapper.class);
        Worker worker = mapper.selectWorkerByIdAndName(3,"王五");
        System.out.println(worker.toString());
        Session.close();
    }
}